<template>
	<view class="follow">
		<uni-swipe-action>
			<uni-swipe-action-item class='follow_box' v-for="(item,index) in dataList" :key='item.id' @change='swipeChange($event, index)'>
				<view class="follow_li" :class="{'follow_on':item.status}">
					<image class="f_li_img" :src="item.cover" mode="aspectFill"></image>
					<view class="f_li_info">
						<view class="name ellipseHide">{{item.cardName}}</view>
						<view class="issuer">
							<view class="issuer_button">发行方</view>
							<text>{{item.merchantName}}</text>
						</view>
						<!-- <view class="price">￥</view> -->
						<view class="price">
							<text style="font-size: 30rpx;">￥</text>
							<text>{{item.price}}</text>
						</view>
					</view>
				</view>
				<template v-slot:right>
					<view class="slot-button" @click="followFunc(item.id)">
						取消<br/>关注
					</view>
				</template>
			</uni-swipe-action-item>			
			<uni-load-more :status="moreStatus" v-if="dataList && dataList.length > 0"></uni-load-more>
			<view style="height: 40rpx;"></view>
		</uni-swipe-action>
		
		<view class="no_info" v-if="dataList.length == 0">
			<image src="/static/my/follow_no.png" mode="widthFix"></image>
			<text>暂无关注</text>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				dataList:[
					// {id:1,name:'',status:false},
					// {id:2,name:'',status:false},
					// {id:3,name:'',status:false},
				],
				// more/loading/noMore
				moreStatus:'more',
				pageSize: 10, //每页记录数
				pageNum: 1, //当前页码
				listTotal: 0, //列表总数
			}
		},
		onLoad() {
			this.getFollowList()
		},
		methods: {
			// 取消关注
			followFunc(id){
				this.$api.setAttention({equityCardId:id,type:2}).then(res=>{
					 if(res.code == 200){
						 this.$queue.showToast('取消关注成功');
						 this.dataList = []
						 this.pageSize = 10
						 this.pageNum = 1
						 this.getFollowList()
					 }
					 
				})

			},
			swipeChange(e,index){
				if(e == 'right'){
					this.dataList[index].status = true
				}else{
					this.dataList[index].status = false
				}
				// console.log('当前状态：'+ e +'，下标：' + index)
			},
			async getFollowList() {
				uni.showLoading({ title:'加载中' })
				this.moreStatus = 'loading'
				var _this = this
				let data = {
					pageSize: this.pageSize,
					pageNum: this.pageNum
				}
				try{
					const res = await this.$api.getAttentionList(data);
					uni.hideLoading()
					this.listTotal = res.result.total
					res.result.records = res.result.records.map(el => {
						el.status = false
						return el;
					})
					if (this.pageNum >= Math.ceil(this.listTotal / this.pageSize)) {
						this.moreStatus = 'noMore'
					} else {
						this.moreStatus = 'more'
					}
					
					if (this.pageNum > 1) {
						this.dataList = this.dataList.concat(res.result.records); //将数据拼接在一起
					} else {
						this.dataList = res.result.records
					}
				}
				catch{
					uni.hideLoading()
				}finally{
					setTimeout(res=>{
						uni.hideLoading()
					},4000)
				}

				console.log(this.dataList)
			},
		},
		// 页面上拉触底事件的处理函数
		onReachBottom: function() {
			console.log("触底了", this.pageNum, Math.ceil(this.listTotal / this.pageSize), this.listTotal)
			if (this.pageNum >= Math.ceil(this.listTotal / this.pageSize)) {
				this.moreShop = 'noMore'
			} else {
				this.moreShop = 'more'
				this.pageNum++; //每触底一次 page + 1;
				this.getFollowList()
			}
		}
	}
</script>

<style scoped>
	page {
		background: #F8FBFF;
	}
	view{
		box-sizing: border-box;
	}
	.follow {
		padding-top: 40rpx;
	}
	.follow_box{
		margin-bottom: 20rpx;
	}
	.follow_li {
		width: 686rpx;
		margin: 0 auto;
		box-sizing: border-box;
		background: #FFFFFF;
		box-shadow: 4rpx 8rpx 16rpx #F3F3F3;
		border-radius: 32rpx;
		display: flex;
		flex-direction: row;
		animation-play-state: paused;
	}
	.follow_on{
		animation-play-state: paused;
		width: 100%;
		border-radius: unset;
		/* margin-left: 60rpx; */
	}
	.follow_li .f_li_img {
		width: 240rpx;
		height: 240rpx;
		border-radius: 32rpx;
		margin-right: 20rpx;
	}
	.f_li_info{
		width: 400rpx;
		padding: 20rpx 0;
	}
	.f_li_info .name {
		font-size: 30rpx;
		color: #000000;
		word-wrap: break-word;
	}

	.f_li_info .issuer {
		font-size: 26rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		margin: 40rpx 0 30rpx;
	}

	.f_li_info .issuer .issuer_button {
		display: inline-block;
		background: linear-gradient(90deg, #3399F2 0%, #4567D4 100%);
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		background-clip: text;
		text-fill-color: transparent;
		font-size: 20rpx;
		border: 2rpx solid #3399F2;
		padding: 2rpx 6rpx;
		border-radius: 8rpx;
		margin-right: 10rpx;
	}

	.f_li_info .price {
		color: #000000;
		font-size: 42rpx;
	}
	.slot-button{
		width: 120rpx;
		height: 100%;
		background: #EE2525;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #FFFFFF;
		font-size: 24rpx;
	}
	
</style>
